<?php
/*
If you would like to edit this file, copy it to your current theme's directory and edit it there.
Theme My Login will always look in your theme's directory first, before using this default template.
*/
?>
<div class="login" id="theme-my-login<?php $template->the_instance(); ?>">
	<?php $template->the_action_template_message( 'register' ); ?>
	<?php $template->the_errors(); ?>
    <form name="registerform" id="registerform<?php $template->the_instance(); ?>" action="<?php $template->the_action_url( 'register' ); ?>" method="post">
        <p>
            <label for="user_login2">ASURITE (ex: jsmith1)</label>
            <input type="text" name="user_login" id="user_login2" onblur="lookupUser();" class="input" value="<?php $template->the_posted_value( 'user_login' ); ?>" size="20" tabindex="1" />
			<img src="<?php bloginfo('template_directory'); ?>/images/ajax-loader.gif" height="32" width="32" alt="loading..." style="display:none" id="loading_icon" />
        </p>
        <p>
            <label for="user_email<?php $template->the_instance(); ?>"><?php _e( 'E-mail', 'theme-my-login' ) ?></label>
            <input type="text" name="user_email" id="user_email<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'user_email' ); ?>" size="20" tabindex="2" />
        </p>
		<?php
		do_action( 'register_form' ); // Wordpress hook
		do_action_ref_array( 'tml_register_form', array( &$template ) ); //TML hook
		?>
		<p id="reg_passmail<?php $template->the_instance(); ?>">
			<?php echo apply_filters( 'tml_register_passmail_template_message', __( 'A password will be e-mailed to you.', $theme_my_login->textdomain ) ); ?>
		</p>
        <p class="submit">
            <input type="submit" name="wp-submit" id="wp-submit<?php $template->the_instance(); ?>" value="<?php _e( 'Register', 'theme-my-login' ); ?>" />
			<input type="hidden" name="redirect_to" value="<?php $template->the_redirect_url( 'register' ); ?>" />
			<input type="hidden" name="instance" value="<?php $template->the_instance(); ?>" />
        </p>
    </form>
	<?php $template->the_action_links( array( 'register' => false ) ); ?>
	<script type="text/javascript">
		var lookupUser = function() {
			jQuery("#loading_icon").show();
			var asurite = jQuery("#user_login2").val();
			if (!isNaN(asurite)) {
				alert("Please do not enter your 1000 digit student id.  Use your My ASU login");
				return;
			}
			jQuery.ajax({
				dataType: 'json',
				success: function (data, textStatus, XMLHttpRequest) {
					jQuery("#loading_icon").hide();
					if (data['person']) {
						var person = data['person'];
						if (person['email'])
							jQuery("#user_email<?php $template->the_instance(); ?>").val(person['email']);
						if (person['firstName'])
							jQuery("#first_name").val(person['firstName']);
						if (person['lastName'])
							jQuery("#last_name").val(person['lastName']);
					}
				},
				url: '<?php bloginfo('template_directory'); ?>/profile_proxy.php?asurite='+asurite
			});
		}
	</script>
</div>